/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
const MenuDataMap = {
  master: [
    '/home',
    '/userManage',
    '/detectorManage',
    '/monitorManage',
    '/alarmManage',
    '/polluteChart',
  ],
  admin: [
    '/home',
    '/userManage',
    '/detectorManage',
    '/monitorManage',
    '/alarmManage',
    '/polluteChart',
  ],
  superuser: ['/home', '/detectorManage', '/monitorManage', '/alarmManage', '/polluteChart'],
  user: ['/home', '/detectorManage', '/monitorManage', '/alarmManage', '/polluteChart'],
};
const roleName2Route = (rolename) => {
  let MenuData;
  switch (rolename) {
    case '超级管理员':
      MenuData = MenuDataMap['master'];
      break;
    case '普通管理员':
      MenuData = MenuDataMap['admin'];
      break;
    case '高级用户':
      MenuData = MenuDataMap['superuser'];
      break;
    case '普通用户':
      MenuData = MenuDataMap['user'];
      break;
    default:
      MenuData = MenuDataMap['user'];
      break;
  }

  return MenuData;
};

export default function access(initialState) {
  let { currentRole, setting } = initialState || {};

  /*  const isAlone = setting
     ? setting.find((i) => i.settingname === 'alone')?.settingvalue === 'True'
     : true;
   // const isAlone = true */

  return {
    normalRouteFilter: (route) => {
      return roleName2Route(currentRole).indexOf(route.path) !== -1;
    },
    surperRouteFilter: () => {
      return currentRole === '超级管理员';
    },
  };
}
